package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.data.entity.MyEvaluationBean;
import com.runen.wnhz.runen.ui.activity.mine.AchievementActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * NAME：薛世杰
 * DATE：2018/5/2
 * EMIAL：zenhac@163.com
 * DESCRIBE：
 */


public class MyTestAdapter extends RecyclerView.Adapter<MyTestAdapter.ViewHodler> {


    private List<MyEvaluationBean.DataBean.ListBean> mlist;
    private Context mContext;
    private LayoutInflater inflater;


    public MyTestAdapter(List<MyEvaluationBean.DataBean.ListBean> mlist, Context mContext) {
        this.mlist = mlist;
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHodler(inflater.inflate(R.layout.my_evaluation_item,parent,false));
    }

    @Override
    public void onBindViewHolder(ViewHodler holder, final int position) {
        holder.tv_type.setText(mlist.get(position).getLesson_name());
        holder.ry_evaluation.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        MyQuestionBankAdapter adapter = new MyQuestionBankAdapter(mContext,mlist.get(position).getTest_list());
        holder.ry_evaluation.setAdapter(adapter);
       /* Glide.with(mContext).load(mlist.get(position).getPic()).into(holder.iv_collection_img);
        holder.tv_collection_title.setText(mlist.get(position).getTitle() +  "标题");
        holder.tv_collection_data.setText("课程有限期：" + mlist.get(position).getExpirytime());
        holder.tv_yikan.setText("已看:" + mlist.get(position).getVcount() + "/" + mlist.get(position).getTcount());
        holder.tv_yidown.setText("已下载:" + mlist.get(position).getDcount() + "/" + mlist.get(position).getTcount());
        */
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position2) {
                Intent intent = new Intent(mContext, AchievementActivity.class);
                intent.putExtra("ltid" , mlist.get(position).getTest_list().get(position2).getTest_id());
                intent.putExtra("mytid",mlist.get(position).getTest_list().get(position2).getMy_tid());
                intent.putExtra("max_score",mlist.get(position).getTest_list().get(position2).getMax_score());
                mContext.startActivity(intent);
            }
        });
      /*  .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, CourseDetailsActivity.class);
                intent.putExtra("lid",mlist.get(position).getLid());
                mContext.startActivity(intent);
            }
        });*/

    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    class ViewHodler extends RecyclerView.ViewHolder{

        @BindView(R.id.tv_type)
        TextView tv_type;

        @BindView(R.id.ry_evaluation)
       RecyclerView ry_evaluation;



        public ViewHodler(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
